<?php
namespace Cyfy;

/**
 * Creating messages.
 *
 * Creating short text messages, which are dynamically shown to users and inform them.
 * There can be more type of messages. Positive or negative.
 *
 * @category cyfy
 * @author Dandelion <dandelion8888@gmail.com>
 * @version 0.1
 */
class Message
{
    /**
     * Default message type. Usually informs user about an action, which ended sucessfully.
     */
    const STATUS = 'status';
    
    /**
     * Message type, which somehow tells user, that there is something wrong, but nothing horrible.
     */
    const WARNING = 'warning';
    
    /**
     * Fatal error message type.
     */
    const ERROR = 'error';
    
    /**
     * Posts a message to screen.
     *
     * Posts a message to user screen, can be used either in normal pages, or in AJAX callback.
     * The message will be shown immediately in both ways.
     *
     * @param string Text to be shown.
     * @param string Type of the message. See constants of class \Cyfy\Message for more information.
     */
    static function set($text, $type = self :: STATUS)
    {
        $_SESSION["templateMessages"] .= "<div class=\"message {$type}\">" . $text . "</div>";
    }
    
    /**
     * Returns a message.
     *
     * Returns text formatted the same way as message.
     * Usefull when you want to display message somewhere inline.
     *
     * @param string Text to be shown.
     * @param string Type of the message. See constants of class \Cyfy\Message for more information.
     * @return string HTML content
     */
    static function get($text, $type = self :: STATUS)
    {
        return "<div class=\"message {$type}\">" . $text . "</div>";
    } 
}